Spring Boot 的配置加载顺序
配置的加载
Spring Boot 可以从 properties 文件、YAML 文件、环境变量和命令行参数获取配置。默认 SpringApplication
将从如下位置加载 application.properties
或 application.yml
文件作为配置。
java -jar project.jar --spring.config.location=/path/to/application.yml
- ......
- A
/config
subdir of the current directory(application.properties
orapplication.yml
) - The current directory(
application.properties
orapplication.yml
) - A classpath
/config
package(application.properties
orapplication.yml
) - The classpath root(
application.properties
orapplication.yml
) @PropertySource
或者@PropertySources
annotations on your@Configuration
classes- Default properties (specified using
SpringApplication.setDefaultProperties
)
根据配置加载的顺序,前面的配置将会覆盖后面的配置项。常见的配置
Copyright © 2015 Powered by MWeb, Theme used GitHub CSS.